package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrdersController")
@RequestMapping("/user/order")
@Api(tags = "C端-下单接口")
@Slf4j
public class OrdersController {
    @Autowired
    private OrderService orderService;
    /**
     * 下单
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "C端-下单")
    public Result orderSubmit(@RequestBody OrdersSubmitDTO dto){
        return orderService.orderSubmit(dto);
    }

    /**
     * 历史订单查询
     * @param dto
     * @return
     */
    @GetMapping("/historyOrders")
    @ApiOperation(value = "C端-历史订单查询")
    public Result page(OrdersPageQueryDTO dto){
        return orderService.page(dto);
    }
    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation(value = "C端-查询订单详情")
    public Result orderDetailFind(@PathVariable Long id){
        return orderService.orderDetailFind(id);
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * 再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result Anotherorder(@PathVariable Long id){
        return orderService.Anotherorder(id);
    }
    /**
     * 取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable Long id){
        return orderService.cancel(id);
    }
    /**
     * 用户催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation("催单")
    public Result reminder(@PathVariable("id") Long id){
        return orderService.reminder(id);
    }
}
